package com.ruiya.staging.goods.cas.service;

import com.ruiya.staging.goods.cas.client.DataIOClient;
import com.ruiya.staging.goods.data.grpc.*;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EchoService {

    @Autowired
    private DataIOClient dataIOClient;

    public Pair<Integer, String> echo(String tid, String sharding, String name) {
        EchoRequest request = EchoRequest.newBuilder()
                .setUri(DataURI.newBuilder()
                        .setTid(tid)
                        .setSharding(sharding)
                        .build())
                .setName(name)
                .build();
        EchoResponse response = this.dataIOClient.echo(request);

        if(response.getStatus().getCode() != 0){
            //TOOD:
        }

        return new ImmutablePair<>(response.getStatus().getCode(), response.getName());
    }




}
